package domain.worm;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Animation;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.appearances.Sprite;

import domain.components.WormsComponent;






// HACER UN METODO WALK QUE SE MUEVA DIRECTAMENTE Y NO HAGA UN COLLIDE



public class Worm extends WormsComponent{

	private int moveCap;
	private double speed;
	private double fallSpeed;
	private WormState state;
	private int dir= -1;
	
	//appearence, habr�a que cambiarlo de lugar. Lo qe mismo que las inicializaciones
	private Sprite still =Sprite.fromImage("/wstill-1.PNG");
	private Sprite[] walkingLeftSprites = new Sprite[15];
	private Animation walkingLeftAnimation;
	private Sprite[] walkingRightSprites = new Sprite[15];
	private Animation walkingRightAnimation;
	private Sprite[] fallSprites = new Sprite[2];
	private Animation fallAnimation;
	private Sprite[] jumpLeftSprites = new Sprite[7];
	private Sprite[] jumpRightSprites = new Sprite[7];
	private Animation jumpLeftAnimation;
	private Animation jumpRightAnimation;
	private Sprite[] bazLeftSprites = new Sprite[7];
	private Sprite[] bazRightSprites = new Sprite[7];
	private Animation bazLeftAnimation;
	private Animation bazRightAnimation;

	
	public Worm(double x, double y) {
		super(25, 25, x, y);
		this.setAppearance(new Circle(Color.PINK, 25));
		this.state = new StateFalling(this);
		moveCap = -10;
		speed = 300;
		fallSpeed = 100;
		
		this.inicializarAnimations();
	
		
	}

	

	@Override
	public boolean isSolid() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	protected void onCollisionWithSolid(WormsComponent gc) {
	}

	@Override
	protected void defineCollide(WormsComponent gc) {
		
	}

	@Override
	protected void effectiveUpdate(DeltaState deltaState) {
		this.getState().update(deltaState);
		/////
	}

	public boolean fall(DeltaState deltaState) {
		// HACER UN STATE QUE SEA "FALLING"
		return this.nonSolidMove(deltaState, this.getFallSpeed(), 0, 1, 0, 0);
	}

	public int getMoveCap() {
		return moveCap;
	}

	public void setMoveCap(int moveCap) {
		this.moveCap = moveCap;
	}

	public double getFallSpeed() {
		return fallSpeed;
	}

	public void setFallSpeed(double fallSpeed) {
		this.fallSpeed = fallSpeed;
	}

	public WormState getState() {
		return state;
	}

	public void setState(WormState state) {
		this.state = state;
	}

	public double getSpeed() {
		return this.speed;
	}

	@Override
	public boolean collideWithRect(WormsComponent comp) {
		return this.rectRectCollide(this, comp);
	}

	@Override
	public boolean collideWithCircle(WormsComponent comp) {
		return this.rectCircleCollide(comp, this);
	}

	@Override
	public boolean collisionNature(WormsComponent comp) {
		return comp.collideWithRect(this);
	}

	public void setDir(int dir) {
		this.dir = dir;
	}

	public int getDir() {
		return dir;
	}
	public boolean canWalk(DeltaState delta, int dir) {
		double nX, nY;
		nX = this.getX() + delta.getDelta()*this.getSpeed()*dir + dir;
		nY = this.getY() -1;
		
		return this.getSceneTableComps().nonCollisionOn(nX, nY, this);
	}

	public void setWalkingLeftAnimation(Animation walkingAnimation) {
		this.walkingLeftAnimation = walkingAnimation;
	}

	public Animation getWalkingLeftAnimation() {
		return walkingLeftAnimation;
	}

	public void setWalkingRightAnimation(Animation walkingRightAnimation) {
		this.walkingRightAnimation = walkingRightAnimation;
	}

	public Animation getWalkingRightAnimation() {
		return walkingRightAnimation;
	}

	public void setStill(Sprite still) {
		this.still = still;
	}
	
	private void inicializarAnimations() {
		//creando la lista de sprites
		walkingLeftSprites[0]=Sprite.fromImage("/wwalk1.PNG");
		walkingLeftSprites[1]=Sprite.fromImage("/wwalk2.PNG");
		walkingLeftSprites[2]=Sprite.fromImage("/wwalk3.PNG");
		walkingLeftSprites[3]=Sprite.fromImage("/wwalk4.PNG");
		walkingLeftSprites[4]=Sprite.fromImage("/wwalk5.PNG");
		walkingLeftSprites[5]=Sprite.fromImage("/wwalk6.PNG");
		walkingLeftSprites[6]=Sprite.fromImage("/wwalk7.PNG");
		walkingLeftSprites[7]=Sprite.fromImage("/wwalk8.PNG");
		walkingLeftSprites[8]=Sprite.fromImage("/wwalk9.PNG");
		walkingLeftSprites[9]=Sprite.fromImage("/wwalk10.PNG");
		walkingLeftSprites[10]=Sprite.fromImage("/wwalk11.PNG");
		walkingLeftSprites[11]=Sprite.fromImage("/wwalk12.PNG");
		walkingLeftSprites[12]=Sprite.fromImage("/wwalk13.PNG");
		walkingLeftSprites[13]=Sprite.fromImage("/wwalk14.PNG");
		walkingLeftSprites[14]=Sprite.fromImage("/wwalk15.PNG");
		
		walkingRightSprites[0]=Sprite.fromImage("/wwalk1r.PNG");
		walkingRightSprites[1]=Sprite.fromImage("/wwalk2r.PNG");
		walkingRightSprites[2]=Sprite.fromImage("/wwalk3r.PNG");
		walkingRightSprites[3]=Sprite.fromImage("/wwalk4r.PNG");
		walkingRightSprites[4]=Sprite.fromImage("/wwalk5r.PNG");
		walkingRightSprites[5]=Sprite.fromImage("/wwalk6r.PNG");
		walkingRightSprites[6]=Sprite.fromImage("/wwalk7r.PNG");
		walkingRightSprites[7]=Sprite.fromImage("/wwalk8r.PNG");
		walkingRightSprites[8]=Sprite.fromImage("/wwalk9r.PNG");
		walkingRightSprites[9]=Sprite.fromImage("/wwalk10r.PNG");
		walkingRightSprites[10]=Sprite.fromImage("/wwalk11r.PNG");
		walkingRightSprites[11]=Sprite.fromImage("/wwalk12r.PNG");
		walkingRightSprites[12]=Sprite.fromImage("/wwalk13r.PNG");
		walkingRightSprites[13]=Sprite.fromImage("/wwalk14r.PNG");
		walkingRightSprites[14]=Sprite.fromImage("/wwalk15r.PNG");
		
		fallSprites[0]=Sprite.fromImage("/wfall1.PNG");
		fallSprites[1]=Sprite.fromImage("/wfall2.PNG");
		
		jumpLeftSprites[0]=Sprite.fromImage("/wjump1.PNG");
		jumpLeftSprites[1]=Sprite.fromImage("/wjump2.PNG");
		jumpLeftSprites[2]=Sprite.fromImage("/wjump3.PNG");
		jumpLeftSprites[3]=Sprite.fromImage("/wjump4.PNG");
		jumpLeftSprites[4]=Sprite.fromImage("/wjump5.PNG");
		jumpLeftSprites[5]=Sprite.fromImage("/wjump6.PNG");
		jumpLeftSprites[6]=Sprite.fromImage("/wjump7.PNG");
		
		jumpRightSprites[0]=Sprite.fromImage("/wjump1r.PNG");
		jumpRightSprites[1]=Sprite.fromImage("/wjump2r.PNG");
		jumpRightSprites[2]=Sprite.fromImage("/wjump3r.PNG");
		jumpRightSprites[3]=Sprite.fromImage("/wjump4r.PNG");
		jumpRightSprites[4]=Sprite.fromImage("/wjump5r.PNG");
		jumpRightSprites[5]=Sprite.fromImage("/wjump6r.PNG");
		jumpRightSprites[6]=Sprite.fromImage("/wjump7r.PNG");
		
		bazLeftSprites[0]=Sprite.fromImage("/wbaz1.PNG");
		bazLeftSprites[1]=Sprite.fromImage("/wbaz2.PNG");
		bazLeftSprites[2]=Sprite.fromImage("/wbaz3.PNG");
		bazLeftSprites[3]=Sprite.fromImage("/wbaz4.PNG");
		bazLeftSprites[4]=Sprite.fromImage("/wbaz5.PNG");
		bazLeftSprites[5]=Sprite.fromImage("/wbaz6.PNG");
		bazLeftSprites[6]=Sprite.fromImage("/wbaz7.PNG");
		
		bazRightSprites[0]=Sprite.fromImage("/wbaz1r.PNG");
		bazRightSprites[1]=Sprite.fromImage("/wbaz2r.PNG");
		bazRightSprites[2]=Sprite.fromImage("/wbaz3r.PNG");
		bazRightSprites[3]=Sprite.fromImage("/wbaz4r.PNG");
		bazRightSprites[4]=Sprite.fromImage("/wbaz5r.PNG");
		bazRightSprites[5]=Sprite.fromImage("/wbaz6r.PNG");
		bazRightSprites[6]=Sprite.fromImage("/wbaz7r.PNG");

		this.bazLeftAnimation = new Animation(0.07, bazLeftSprites);
		this.bazRightAnimation = new Animation(0.07, bazRightSprites);
		
		this.jumpLeftAnimation = new Animation(0.1, jumpLeftSprites);
		this.jumpRightAnimation = new Animation(0.1, jumpRightSprites);

		
		this.fallAnimation = new Animation(0.07, fallSprites);
		
		this.walkingRightAnimation = new Animation(0.07, walkingRightSprites);
		this.walkingLeftAnimation = new Animation(0.07, walkingLeftSprites);		
	}



	public Sprite getStill() {
		return still;
	}



	public void setFallAnimation(Animation fallAnimation) {
		this.fallAnimation = fallAnimation;
	}



	public Animation getFallAnimation() {
		return fallAnimation;
	}

	public void setJumpLeftAnimation(Animation jumpLeftAnimation) {
		this.jumpLeftAnimation = jumpLeftAnimation;
	}



	public Animation getJumpLeftAnimation() {
		return jumpLeftAnimation;
	}



	public void setJumpRightAnimation(Animation jumpRightAnimation) {
		this.jumpRightAnimation = jumpRightAnimation;
	}



	public Animation getJumpRightAnimation() {
		return jumpRightAnimation;
	}



	public void setBazLeftAnimation(Animation bazLeftAnimation) {
		this.bazLeftAnimation = bazLeftAnimation;
	}



	public Animation getBazLeftAnimation() {
		return bazLeftAnimation;
	}



	public void setBazRightAnimation(Animation bazRightAnimation) {
		this.bazRightAnimation = bazRightAnimation;
	}



	public Animation getBazRightAnimation() {
		return bazRightAnimation;
	}
	

}
